<template>
  <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
             label-width="120px">
      <el-form-item label="采购方编码" prop="purchaserHqCode">
        <el-input v-model="queryParams.purchaserHqCode" placeholder="请输入采购方总部编码"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="产品名称" prop="productName">
        <el-input v-model="queryParams.productName" placeholder="请输入产品名称"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="生产工单编码" prop="woNo">
        <el-input v-model="queryParams.woNo" placeholder="请输入生产工单编码"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-hasPermi="['develop:FactoryProduceWork:add']">新增
        </el-button>
      </el-form-item>
    </el-form>


    <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table"
              :max-height="tableMaxHeight">
      <el-table-column type="selection" width="55" align="center"/>
      <!--            <el-table-column label="采购方总部编码" width="150" align="center" prop="purchaserHqCode"/>-->
      <el-table-column label="生产订单编号" width="150" align="center" prop="ipoNo"/>
      <el-table-column label="生产工单编码" width="150" align="center" prop="woNo"/>
      <el-table-column label="产品名称" width="150" align="center" prop="productName" show-overflow-tooltip/>
      <el-table-column label="厂家物料编码" width="150" align="center" prop="materialsCode"/>
      <el-table-column label="厂家物料描述" width="150" align="center" prop="materialsDescription"/>
      <el-table-column label="物料批次" width="150" align="center" prop="materialsBatch"/>
      <el-table-column label="生产数量" width="150" align="center" prop="amount"/>
      <el-table-column label="计量单位" width="150" align="center" prop="unit"/>

      <el-table-column label="计划开始日期" align="center" prop="planStartDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.planStartDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="计划完成日期" align="center" prop="planFinishDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.planFinishDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实际开始日期" align="center" prop="actualStartDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.actualStartDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实际完成日期" align="center" prop="actualFinishDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.actualFinishDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!--<el-table-column label="计划开始日期" width="150" align="center" prop="planStartDate"/>
      <el-table-column label="计划完成日期" width="150" align="center" prop="planFinishDate"/>
      <el-table-column label="实际开始日期" width="150" align="center" prop="actualStartDate"/>
      <el-table-column label="实际完成日期" width="150" align="center" prop="actualFinishDate"/>-->
      <el-table-column label="工单状态" width="150" align="center" prop="woStatus"/>
      <el-table-column label="工艺路线编码" width="150" align="center" prop="processRouteNo"/>
      <el-table-column label="产品型号规格" width="150" align="center" prop="modelSpec"/>
      <el-table-column label="操作" align="center" width="250" fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button @click="showGxList(scope.row)" icon="el-icon-s-claim" size="mini" type="text">
            查看工序
          </el-button>
          <!-- <el-button @click="shedingGygx(scope.row)" icon="el-icon-s-claim" size="mini" type="text">
            工艺工序
          </el-button> -->
          <!-- <el-button @click="shedingGygx(scope.row)"  icon="el-icon-s-claim" size="mini" type="text">
             设定工单计划
           </el-button>-->
<!--          <el-button @click="qualityTesting(scope.row)" icon="el-icon-s-claim" size="mini" type="text">-->
<!--            产品质检-->
<!--          </el-button>-->

          <el-button  @click="chaijie(scope.row)"  icon="el-icon-setting" size="mini" type="text">
            材料拆解
          </el-button>
          <el-button  size="mini" type="text" icon="el-icon-document" @click="yongliaoMingxi(scope.row)">
            用料明细
          </el-button>
          <el-button @click="qualityTest(scope.row)"  icon="el-icon-view" size="mini" type="text">
            质检情况
          </el-button>
          <el-button  @click="shengchanDoGoodsSale(scope.row)"  icon="el-icon-setting" size="mini" type="text">
            生产过程
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-edit"
                     @click="handleUpdate(scope.row)" v-hasPermi="['develop:FactoryProduceWork:edit']">修改
          </el-button>
          <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                         style="margin-left: 10px;">
            <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                       v-hasPermi="['develop:FactoryProduceWork:remove']">删除
            </el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>

    <factoryProduceWork-form ref="form" @ok="getList"></factoryProduceWork-form>
    <factory-test-quality ref="qualityTesting" @ok="getList"></factory-test-quality>
    <shedingGygx-form ref="shedingGygxForm" @ok="getList"></shedingGygx-form>
    <showGongxu-list ref="showGongxu" @ok="getList"></showGongxu-list>
    <chajie-form @ok="getList" ref="chaijieForm"></chajie-form>
    <yongliaoMingxi-form-list ref="yongliaoMingxiForm" @ok="getList"></yongliaoMingxi-form-list>
    <factory-test-quality-goods ref="qualityTestingGoods" @ok="getList"> </factory-test-quality-goods>
    <shengchanDoGoodsSale-form @ok="getList" ref="shengchanDoGoodsSaleForm"></shengchanDoGoodsSale-form>
  </el-dialog>
</template>

<script>
import {deleteAction, getAction} from '@/api/manage'
import FactoryProduceWorkForm from '@/views/develop/factory/factoryProduceWork/module/FactoryProduceWorkForm'
import FactoryTestQuality from "@/views/develop/factory/factoryTestQuality/FactoryTestQuality.vue";
import ShedingGygxForm from "@/views/develop/factory/factoryProducePlanGongxu/ShedingGygxForm.vue";
import ChajieForm from "@/views/develop/projectBaseInfo/prjForGoodsIn/ChajieForm.vue";
import YongliaoMingxiFormList from "@/views/develop/goodsSaleMaterial/module/YongliaoMingxiFormList.vue";
import FactoryTestQualityGoods from "@/views/develop/factory/factoryTestQuality/FactoryTestQualityGoods.vue";
import ShengchanDoGoodsSaleForm from "@/views/develop/goodsSale/module/ShengchanDoGoodsSaleForm.vue";
import ShowGongxuList from '@/views/develop/goodsSaledoGongxu/module/GoodsSaleGongxuForm.vue'

export default {
  name: "ShengchangongdanFormList",
  components: {
    ShengchanDoGoodsSaleForm,
    FactoryTestQualityGoods,
    YongliaoMingxiFormList,
    ChajieForm,
    FactoryProduceWorkForm,
    FactoryTestQuality,
    ShedingGygxForm,
    ShowGongxuList
  },
  data() {
    return {
      title: '',
      // 遮罩层
      open: false,
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工单信息表格数据
      dataList: [],
      ipoNo: null,
      produceId: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        status: null,
        purchaserHqCode: null,
        ipoNo: null,
        supplierCode: null,
        supplierName: null,
        woNo: null,
        categoryCode: "60",
        subclassCode: "60004",
        materialsCode: null,
        materialsDescription: null,
        materialsBatch: null,
        amount: null,
        unit: null,
        planStartDate: null,
        planFinishDate: null,
        actualStartDate: null,
        actualFinishDate: null,
        woStatus: null,
        entityCode: null,
        processRouteNo: null,
        voltageLevel: null,
        dataSource: null,
        dataSourceCreateTime: null,
        ownerId: null,
        openId: null,
        modelSpec: null,
        subcategoryCode: null,
        subcategoryName: null,
        productName: null,
        reactanceRatio: null,
        proNo: null,
        planNo: null,
        projectId: null,
      },
      url: {
        list: '/factoryProduceWork/factoryProduceWork/list',
        remove: '/factoryProduceWork/factoryProduceWork/',
        export: '/factoryProduceWork/factoryProduceWork/export',
      },
      tableMaxHeight: window.innerHeight - 320,
    };
  },
  created() {
    //this.getList();
    window.addEventListener('resize', this.getTableHeight);
  },
  destroyed() {
    window.removeEventListener('resize', this.getTableHeight)
  },
  methods: {
      showGxList(row) {
        this.$refs.showGongxu.xunjianShow(row,true);
      },
    shedingGygx(row) {
      this.$refs.shedingGygxForm.show(row);
    },
    show(row) {
      this.queryParams.ipoNo = row.ipoNo;
      this.produceId = row.id;
      this.ipoNo = row.ipoNo;
      this.open = true;
      this.title = "工单信息";
      this.getList();
    },
    showByProject(row) {
      this.queryParams.projectId = row.id;
      this.produceId = row.id;
      this.ipoNo = row.ipoNo;
      this.open = true;
      this.title = "工单信息";
      this.getList();
    },
    /** 查询工单信息列表 */
    getList() {
      this.loading = true;
      getAction(this.url.list, this.queryParams).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getTableHeight() {
      this.tableHeight = window.innerHeight - 320
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.form.handleAdd(this.produceId,this.ipoNo);
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs.form.handleUpdate(row);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      deleteAction(this.url.remove, ids).then(response => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(this.url.export, {
        ...this.queryParams
      }, `factoryProduceWork_${new Date().getTime()}.xlsx`)
    },
    qualityTesting(row) {
      this.$refs.qualityTesting.showByWorkOrder(row);
    },


    chaijie(row){
      let params = {"id":row.goodsSaleId}
      this.$refs.chaijieForm.chaijieGoods(params);
    },
    yongliaoMingxi(row){
      let params = {"id":row.goodsSaleId}
      this.$refs.yongliaoMingxiForm.show(params);
    },
    qualityTest(row){
      let params = {"id":row.goodsSaleId}
      this.$refs.qualityTestingGoods.showByGoodsSale(params);
    },

    shengchanDoGoodsSale(row){
      this.$refs.shengchanDoGoodsSaleForm.show(row);
    },




  }
};
</script>
